package org.chen.flight.util;

import org.chen.common.flight.request.FlightSearchRequest;
import org.springframework.stereotype.Component;

// UrlBuilder.java - URL构建工具
@Component
public class UrlBuilder {
    
    /**
     * 构建携程搜索URL
     */
    public static String buildCtripSearchUrl(FlightSearchRequest request) {
        String route = request.getDeparture() + "-" + request.getDestination();
        
        if ("oneway".equals(request.getTripType())) {
            return String.format(
                "https://flights.ctrip.com/international/search/api/flightlist/oneway-%s?_=1&depdate=%s&cabin=y_s&containstax=1&adult=%d&child=%d&infant=%d",
                route, request.getDepartDate(), request.getAdults(), request.getChildren(), request.getInfants()
            );
        } else {
            String dateRange = request.getDepartDate() + "_" + request.getReturnDate();
            return String.format(
                "https://flights.ctrip.com/international/search/api/flightlist/round-%s?depdate=%s&cabin=y_s&adult=%d&child=%d&infant=%d",
                route, dateRange, request.getAdults(), request.getChildren(), request.getInfants()
            );
        }
    }
}